package com.example.back.Repository;

import com.example.back.Entity.OrderItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface OrderItemRepository extends JpaRepository<OrderItem, Long> {
    Page<OrderItem> findAllByBuyerId(long buyerId, Pageable pageable);
    OrderItem findOrderByOrderId(long orderId);
    Page<OrderItem> findAllBySellerId(long sellerId, Pageable pageable);
    Page<OrderItem> findAllByProductNameContainsAndBuyerId(String PNCB,long BId,Pageable pageable);
    Page<OrderItem> findAllByProductNameContainsAndSellerId(String PNCS,long SId,Pageable pageable);
    Page<OrderItem> findAllByStateAndSellerId(Pageable pageable,String state,long sellerId);
    //这里要有更新订单状态的接口
    @Transactional
    @Modifying
    @Query("update OrderItem tempOrder set tempOrder.state=:newState where tempOrder.orderId=:orderId")
    void setNewState(String newState,long orderId);
}
